package com.telsoft.hms.data;

import java.util.ArrayList;
import java.util.List;

import com.telsoft.hms.entity.ETT_InfoRegisPatient;
import com.telsoft.hms.lib.admin.client.data.ClientDataPreprocessor;

public class GetInfoRigsPatient_DATA extends ClientDataPreprocessor {
	public ETT_InfoRegisPatient getInfoRigsPatient(int patientID, int regisID,
			String hospitalKey) throws Exception {
		// List<ETT_InfoRegisPatient> lst = new
		// ArrayList<ETT_InfoRegisPatient>();
		ETT_InfoRegisPatient ett = null;
		try {
			String strSQL = "SELECT c.patient_type_code, c.hie_general_rate, c.hie_special_svr_rate, c.pharmacy_outlist_rate, c.hie_transport_rate, "
					+ " c.examine_line_id, c.hie_no, c.hie_hospital_code, c.hie_type, c.hie_letter, c.hie_fromdate, c.hie_todate, c.hie_effect_from, "
					+ " c.hie_effect_to, b.address, b.birthday, a.age_type, a.city_id, a.contact_address, a.contact_who, a.contact_phone, a.county_id, "
					+ " b.email, b.full_name, b.patient_code, a.reg_date, b.sex, b.occupation_id, a.workplace, a.introduceplace_type, a.state_id, b.nationality_id, "
					+ " b.ethnic_id, b.mobile, b.phone, b.id_no, b.pin, b.passport_no, b.patient_image "
					+ " FROM registration a, patient b, treatment c WHERE b.patient_id = a.patient_id AND a.registration_id = c.registration_id "
					+ " AND a.status = 1 AND a.registration_id = ? AND b.patient_id = ? AND c.treatment_type = 4";
			open(hospitalKey);
			mStmt = mConnection.prepareStatement(strSQL);
			mStmt.setInt(1, regisID);
			mStmt.setInt(2, patientID);
			mRs = mStmt.executeQuery();
			if (mRs.next()) {
				ett = new ETT_InfoRegisPatient();
				ett.setPatientTypeCode(mRs.getString("patient_type_code"));
				ett.setHieGeneralRate(mRs.getInt("hie_general_rate"));
				ett.setHieSpecialSvrRate(mRs.getInt("hie_special_svr_rate"));
				ett.setPharmacyOutlistRate(mRs.getInt("pharmacy_outlist_rate"));
				ett.setHieTransportRate(mRs.getInt("hie_transport_rate"));
				ett.setExamineLineID(mRs.getInt("examine_line_id"));
				ett.setHieNo(mRs.getString("hie_no"));
				ett.setHieHospitalCode(mRs.getString("hie_hospital_code"));
				ett.setHieType(mRs.getString("hie_type"));
				ett.setHieLetter(mRs.getString("hie_letter"));
				ett.setHieFromDate(mRs.getDate("hie_fromdate"));
				ett.setHieToDate(mRs.getDate("hie_todate"));
				ett.setHieEffectFrom(mRs.getDate("hie_effect_from"));
				ett.setHieEffectTo(mRs.getDate("hie_effect_to"));
				ett.setAddress(mRs.getString("address"));
				ett.setBirthday(mRs.getDate("birthday"));
				ett.setAgeType(mRs.getString("age_type"));
				ett.setCityID(mRs.getInt("city_id"));
				ett.setContactAddress(mRs.getString("contact_address"));
				ett.setContactWho(mRs.getString("contact_who"));
				ett.setContactPhone(mRs.getString("contact_phone"));
				ett.setCountyID(mRs.getInt("county_id"));
				ett.setEmail(mRs.getString("email"));
				ett.setFullName(mRs.getString("full_name"));
				ett.setPatientCode(mRs.getString("patient_code"));
				ett.setRegDate(mRs.getDate("reg_date"));
				ett.setSex(mRs.getString("sex"));
				ett.setOccupationID(mRs.getInt("occupation_id"));
				ett.setWorkPlace(mRs.getString("workplace"));
				ett.setIntroducePlaceType(mRs.getString("introduceplace_type"));
				ett.setStateID(mRs.getInt("state_id"));
				ett.setNationalityID(mRs.getInt("nationality_id"));
				ett.setEthnicID(mRs.getInt("ethnic_id"));
				ett.setMobile(mRs.getString("mobile"));
				ett.setPhone(mRs.getString("phone"));
				ett.setIdNO(mRs.getString("id_no"));
				ett.setPin(mRs.getString("pin"));
				ett.setPassportNo(mRs.getString("passport_no"));
				ett.setPatientImage(mRs.getBlob("patient_image"));
			}
			return ett;
		} catch (Exception ex) {
			throw new Exception(ex.getMessage());
		} finally {
			close(mRs);
			close(mStmt);
			close(mConnection);
		}
	}
}
